home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / c4 / pro5 / alarm.c next >
Encoding:
C/C++ Source or Header  |  1988-11-09  |  5.5 KB  |  245 lines

  1. /*
  2.  
  3.     Program:    alarm.c
  4.     Author:        A. Michael Ferris
  5.     Date:        10/13/88
  6.     Function:
  7.  
  8.     Provide a method for popup reminders to the display screen
  9.     while other applications execute.
  10.  
  11.     This program uses the Vio popup routines to steal the video
  12.     display and show a short reminder.  It also contains some
  13.     primative examples of manipulating the display screen using
  14.     Vio calls.
  15.  
  16.     Usage:        detach alarm hh mm [any message up to 70 chars]
  17.  
  18.     Notes:
  19.  
  20.     To compile with MSC 5.10 - cl -Lp -G2 alarm.c
  21.  
  22. */
  23.  
  24. #define    INCL_BASE
  25. #define    INCL_SUB
  26. #include <os2.h>
  27. #include <stdio.h>
  28. #include <conio.h>
  29. #include <string.h>
  30. #include <stdarg.h>
  31. #include <malloc.h>
  32.  
  33.  
  34. /*
  35.  
  36.     Character mode based definitions and global variable for OS/2 1.0
  37.  
  38.     amf        01/27/88
  39.  
  40. */
  41.  
  42. /*
  43.     Screen Color Definitions for EGA/CGA/VGA display adapters in
  44.     color text mode
  45. */
  46.  
  47. #define    BLACK    0
  48. #define    BLUE    1
  49. #define    GREEN    2
  50. #define    CYAN    3
  51. #define    RED     4
  52. #define    MAGENTA    5
  53. #define    BROWN    6
  54. #define    WHITE    7
  55.  
  56. #define    BRIGHT    8    /* High Intensity */
  57.  
  58. /*     Macro to set a char to the video attributes desired */
  59.  
  60. #define    attr(BACK,FORE)    (BACK << 4) | (FORE)
  61.  
  62. /*    Default to bright white on blue     */
  63.  
  64. UCHAR    curattr = attr(BLUE,WHITE+BRIGHT);
  65.  
  66. USHORT    oldcol,oldrow;    /* Where cursor was when we started */
  67. USHORT    curcol, currow;    /* Current Row and Column */
  68. USHORT     curback = BLUE;    /* Default background is blue    */
  69. USHORT    curfore = WHITE + BRIGHT;   /* Default foreground */
  70. UCHAR    space = ' ';
  71.  
  72. UCHAR    ESCAPE[]="Press ESC to continue";
  73.  
  74. void main(argc, argv)
  75. UINT    argc;
  76. UCHAR    **argv;
  77. {
  78.     USHORT fWait = VP_WAIT | VP_OPAQUE;
  79.     UCHAR    ch,*message;
  80.     DATETIME dateTime;
  81.     USHORT    i;
  82.     USHORT    handtype, flagword;
  83.  
  84.     /* Verify that we are a detaching the process */
  85.     DosQHandType(0,(unsigned far *)&handtype,
  86.         (unsigned far *)&flagword);
  87.     if ((flagword & 1) | (flagword & 2))
  88.         {
  89.                 VioPopUp(&fWait,0);
  90.         cls();
  91.         drawbox(0,0,10,79);
  92.         curattr=attr(BLACK,WHITE);
  93.         VioWrtNAttr(&curattr,80*15,11,0,0);
  94.         curattr = attr(BLUE,WHITE+BRIGHT);
  95.         center(4,"Alarm must run as a detached process");
  96.         center(6,ESCAPE);
  97.         DosBeep(400,100);
  98.         getkey(27);
  99.         VioEndPopUp(0);
  100.         DosExit(1,1);
  101.     }
  102.  
  103.     if (argc < 3)    /* Check to see that time is on command line */
  104.     {
  105.         VioPopUp(&fWait,0);
  106.         cls();
  107.         drawbox(0,0,10,79);
  108.         curattr=attr(BLACK,WHITE);
  109.         VioWrtNAttr(&curattr,80*15,11,0,0);
  110.         curattr = attr(BLUE,WHITE+BRIGHT);
  111.         center(4,"Usage: detach alarm hh mm [message]");
  112.         center(6,ESCAPE);
  113.         DosBeep(400,100);
  114.         getkey(27);
  115.         VioEndPopUp(0);
  116.         DosExit(1,1);
  117.     }
  118.  
  119.     while (!(dateTime.hours == atoi(argv[1]) &&
  120.         dateTime.minutes == atoi(argv[2])))
  121.             {
  122.             DosGetDateTime(&dateTime);
  123.             DosSleep(1000L);
  124.             }
  125.  
  126.     message = malloc(81);
  127.     VioPopUp(&fWait, 0);                /* Creates a pop-up screen */
  128.     cls();
  129.     drawbox(0,0,10,79);
  130.     curattr=attr(BLACK,WHITE);
  131.     VioWrtNAttr(&curattr,80*15,11,0,0);
  132.     message[0] = 0;
  133.     curattr = attr(BLUE,WHITE+BRIGHT);
  134.     center(1,"Alarm Version 1.1 - Reminder");
  135.     sprintf(message,"Time: %02d:%02d",atoi(argv[1]), atoi(argv[2]));
  136.     center(3, message);
  137.     message[0] = 0;
  138.     if (argc > 3)
  139.     {
  140.         for (i = 3; i < argc; i++)
  141.         {
  142.             message = strcat(message, argv[i]);
  143.             message = strcat(message, " ");
  144.         }
  145.     }
  146.     curattr = attr(BLUE,BROWN+BRIGHT);
  147.     center(6,message);
  148.     curattr = attr(BLUE,WHITE+BRIGHT);
  149.     center(9, ESCAPE);
  150.     for (i = 0 ; i < 3 ; i++)
  151.         DosBeep(400,100);
  152.     getkey(27);
  153.     VioEndPopUp(0);                     /* Ends the pop-up screen  */
  154.     return;
  155. }
  156.  
  157.  
  158. drawbox(frow,fcol,trow,tcol)    /* Draw box */
  159. short    frow,fcol,trow,tcol;
  160. {
  161.     static UCHAR    uleft     = 201;
  162.     static UCHAR    uright  = 187;
  163.     static UCHAR    lleft    = 200;
  164.     static UCHAR     lright    = 188;
  165.     static UCHAR    horiz    = 205;
  166.     static UCHAR     vert    = 186;
  167.     static UCHAR     ljoin    = 204;
  168.     static UCHAR     rjoin    = 185;
  169.  
  170.     USHORT    i;
  171.  
  172.     VioWrtNChar(&horiz, tcol-fcol, frow, fcol, 0);
  173.     VioWrtNChar(&horiz, tcol-fcol, trow, fcol, 0);
  174.     for (i = frow; i < trow; i++)
  175.     {
  176.         VioWrtNChar(&vert,1,i,fcol,0);
  177.         VioWrtNChar(&vert,1,i,tcol,0);
  178.     }
  179.     VioWrtNChar(&uleft,1,frow,fcol,0);
  180.     VioWrtNChar(&uright,1,frow,tcol,0);
  181.     VioWrtNChar(&lleft,1,trow,fcol,0);
  182.     VioWrtNChar(&lright,1,trow,tcol,0);
  183. }
  184.  
  185. cls()            /* Clear the screen with current attributes */
  186. {
  187.     UCHAR    buff[2];
  188.  
  189.     buff[0] = ' ';
  190.     buff[1] = curattr;
  191.     VioScrollUp(0, 0, -1, -1, -1, (char far *) buff, 0);
  192. }
  193.  
  194. gotoxy(row, col)        /* Position cursor to row and col     */
  195. USHORT     row, col;
  196. {
  197.     if (row > 24)
  198.         row = 24;
  199.     else if (row < 0) row = 0;
  200.     if (col > 79)
  201.         col = 79;
  202.     else if (col < 0) col = 0;
  203.     VioSetCurPos(row, col, 0);
  204.     currow = row; /* Set current row and column */
  205.     curcol = col;
  206. }
  207.  
  208. center(row, string)        /* Center a string on a row    */
  209. USHORT    row;
  210. UCHAR     *string;
  211. {
  212.     USHORT    col;
  213.  
  214.     col = (80 - strlen(string)) / 2;
  215.     gotoxy(row, col);
  216.     VioWrtCharStrAtt((char far *) string, strlen(string), currow, curcol,
  217.     &curattr, 0);
  218.     curcol += strlen(string); /* Set cursor to last char of string +1 */
  219.     gotoxy(currow,curcol);
  220. }
  221.  
  222. vioprintf(fmt)    /* Simulate printf function for VIO OS/2 handler    */
  223. UCHAR *fmt;    /* Does not parse newlines etc.                */
  224. {
  225.     UCHAR *string;    /* Storage for the formatted string */
  226.  
  227.     va_list    arg_ptr;
  228.     va_start(arg_ptr, fmt);
  229.     gotoxy(currow,curcol);
  230.     string = malloc(128);
  231.     vsprintf(string, fmt, arg_ptr);
  232.     va_end(arg_ptr);
  233.     VioWrtCharStrAtt((char far *) string, strlen(string),
  234.     currow, curcol,    &curattr, 0);
  235.     curcol += strlen(string);
  236.     gotoxy(currow,curcol);
  237.     free(string);
  238. }
  239.  
  240. getkey(UCHAR key)
  241. {
  242. UCHAR    ch;
  243.  
  244.     while ((ch = getch()) != key);
  245. }